﻿namespace System.ServiceModel.DomainServices.Client
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    internal class EntityKey<T1, T2> : EntityKey, IEquatable<EntityKey<T1, T2>>
    {
        private T1 _v1;
        private T2 _v2;

        public EntityKey(T1 v1, T2 v2)
        {
            EntityKey.VerifyKeyValueNotNull(v1);
            EntityKey.VerifyKeyValueNotNull(v2);
            this._v1 = v1;
            this._v2 = v2;
        }

        public override bool Equals(object obj)
        {
            return this.Equals((EntityKey<T1, T2>) obj);
        }

        public bool Equals(EntityKey<T1, T2> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }
            return (EqualityComparer<T1>.Default.Equals(this._v1, other._v1) && EqualityComparer<T2>.Default.Equals(this._v2, other._v2));
        }

        internal override void FormatKey(StringBuilder sb)
        {
            EntityKey.FormatKeyValue<T1>(sb, this._v1);
            EntityKey.FormatKeyValue<T2>(sb, this._v2);
        }

        public override int GetHashCode()
        {
            return (this._v1.GetHashCode() ^ this._v2.GetHashCode());
        }
    }
}

